<template>
	<el-main class="bg edit_wrap">
		<el-form ref="form" :model="form" status-icon label-width="120px">

							<el-col :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="课程名称" prop="course_name">
												<el-input id="course_name" v-model="form['course_name']" placeholder="请输入课程名称" :disabled="disabledObj['course_name_isDisabled']"></el-input>
					<div >{{form['course_name']}}</div>
											</el-form-item>
			</el-col>
								<el-col :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="课程类型" prop="course_type">
												<el-input id="course_type" v-model="form['course_type']" placeholder="请输入课程类型" :disabled="disabledObj['course_type_isDisabled']"></el-input>
					<div >{{form['course_type']}}</div>
											</el-form-item>
			</el-col>
								<el-col :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="考试序号" prop="course_time">
												<el-input id="course_time" v-model="form['course_time']" placeholder="请输入考试序号"
							   :disabled="disabledObj['course_time_isDisabled']"></el-input>
					<div>{{form['course_time']}}</div>
											</el-form-item>
			</el-col>
								<el-col :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="课程教师" prop="course_teacher">
													<el-select id="course_teacher" v-model="form['course_teacher']" :disabled="disabledObj['course_teacher_isDisabled']">
							<el-option v-for="o in list_user_course_teacher" :key="o['username']" :label="o['nickname'] + '-' + o['username']"
									   :value="o['user_id']">
							</el-option>
						</el-select>
						<el-select :disabled="true">
							<el-option v-for="o in list_user_course_teacher" :key="o['username']" :label="o['nickname'] + '-' + o['username']"
									   :value="o['user_id']">
							</el-option>
						</el-select>
											</el-form-item>
			</el-col>
<!--								<el-col v-if="user_group === '管理员' || $check_field('get','teacher_name') || $check_field('add','teacher_name') || $check_field('set','teacher_name')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">-->
<!--				<el-form-item label="教师姓名" prop="teacher_name">-->
<!--												<el-input id="teacher_name" v-model="form['teacher_name']" placeholder="请输入教师姓名"-->
<!--							  v-if="user_group === '管理员' || (form['course_score_id'] && $check_field('set','teacher_name')) || (!form['course_score_id'] && $check_field('add','teacher_name'))" :disabled="disabledObj['teacher_name_isDisabled']"></el-input>-->
<!--					<div v-else-if="$check_field('get','teacher_name')">{{form['teacher_name']}}</div>-->
<!--											</el-form-item>-->
<!--			</el-col>-->
								<el-col :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="学生学号" prop="student_id">
												<el-input id="student_id" v-model="form['student_id']" placeholder="请输入学生学号" :disabled="disabledObj['student_id_isDisabled']"></el-input>
					<div>{{form['student_id']}}</div>
											</el-form-item>
			</el-col>
								<el-col :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="学生姓名" prop="student_name">
												<el-input id="student_name" v-model="form['student_name']" placeholder="请输入学生姓名" :disabled="disabledObj['student_name_isDisabled']"></el-input>
					<div>{{form['student_name']}}</div>
											</el-form-item>
			</el-col>
								<el-col :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="录入日期" prop="entry_date">
								<el-date-picker :disabled="disabledObj['entry_date_isDisabled']" id="entry_date"
						v-model="form['entry_date']" type="date" placeholder="选择日期">
					</el-date-picker>
					<div>{{form['entry_date']}}</div>
							</el-form-item>
			</el-col>
								<el-col :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="学生成绩" prop="student_achievements">
								<el-input-number id="student_achievements" v-model.number="form['student_achievements']" :disabled="disabledObj['student_achievements_isDisabled']"></el-input-number>
					<div>{{form['student_achievements']}}</div>
							</el-form-item>
			</el-col>
								<el-col :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="教师评语" prop="teacher_comments">
								<el-input type="textarea" id="teacher_comments" v-model="form['teacher_comments']" placeholder="请输入教师评语" :disabled="disabledObj['teacher_comments_isDisabled']"></el-input>
					<div>{{form['teacher_comments']}}</div>
							</el-form-item>
			</el-col>
			<el-col :xs="24" :sm="12" :lg="8" class="el_form_btn_warp">
				<el-form-item>
					<el-button type="primary" @click="submit()">提交</el-button>
					<el-button @click="cancel()">取消</el-button>
				</el-form-item>
			</el-col>

		</el-form>
	</el-main>
</template>

<script>

	import axios from "axios";

  export default {
		data() {
			return {
				field: "course_score_id",
				url_add: "~/api/course_score/add?",
				url_set: "~/api/course_score/set?",
				url_get_obj: "~/api/course_score/get_obj?",
				url_upload: "~/api/course_score/upload?",

				query: {
					"course_score_id": 0,
				},

				form: {
								"course_name":  '', // 课程名称
										"course_type":  '', // 课程类型
										"course_time":  '', // 课程时间
										"course_teacher": 0, // 课程教师
										"teacher_name":  '', // 教师姓名
										"student_id":  '', // 学生学号
										"student_name":  '', // 学生姓名
										"entry_date":  '', // 录入日期
										"student_achievements":  0, // 学生成绩
										"teacher_comments":  '', // 教师评语
											"course_score_id": 0, // ID

				},
				disabledObj:{
								"course_name_isDisabled": false,
										"course_type_isDisabled": false,
										"course_time_isDisabled": false,
										"course_teacher_isDisabled": false,
										"teacher_name_isDisabled": false,
										"student_id_isDisabled": false,
										"student_name_isDisabled": false,
										"entry_date_isDisabled": false,
					          "student_achievements_isDisabled": false,
										"teacher_comments_isDisabled": false,
										},
					// 用户列表
				list_user_course_teacher: [],
			}
		},
		methods: {
				/**
			 * 获取教师用户用户列表
			 */
			async get_list_user_course_teacher() {
                // if(this.user_group !== "管理员" && this.form["course_teacher"] === 0) {
                //     this.form["course_teacher"] = this.user.user_id;
                // }
                var json = await axios.get("~/api/user/get_list?user_group=教师用户");
                if(json.result && json.result.list){
                    this.list_user_course_teacher = json.result.list;
                }
                else if(json.error){
                    console.error(json.error);
                }
			},
					get_user_course_teacher(id){
				var obj = this.list_user_course_teacher.getObj({"user_id":id});
				var ret = "";
				if(obj){
					if(obj.nickname){
						ret = obj.nickname;}
					else{
						ret = obj.username;
					}
				}
				return ret;
			},
			/**
			 * 获取对象之前
			 * @param {Object} param
			 */
			get_obj_before(param) {
				var form = "";
																							// 获取缓存数据附加
				form = $.db.get("form");
							$.push(this.form ,form);

				if(this.form && form){
					Object.keys(this.form).forEach(key => {
						Object.keys(form).forEach(dbKey => {
							// if(dbKey === "charging_standard"){
							// 	this.form['charging_rules'] = form[dbKey];
							// 	this.disabledObj['charging_rules_isDisabled'] = true;
							// };
							if(key === dbKey){
								this.disabledObj[key+'_isDisabled'] = true;
							}
						})
					})
				}
																        if (this.form["entry_date"].indexOf("-")===-1){
          this.form["entry_date"] = this.$toTime(parseInt(this.form["entry_date"]),"yyyy-MM-dd")
        }
									$.db.del("form");
				return param;
			},

			/**
			 * 获取对象之后
			 * @param {Object} json
			 * @param {Object} func
			 */
			get_obj_after(json, func){


																							        if(this.form["entry_date"]=="0000-00-00"){
          this.form["entry_date"] = null;
        }
				if(parseInt(this.form["entry_date"]) > 9999){
					this.form["entry_date"] = this.$toTime(parseInt(this.form["entry_date"]),"yyyy-MM-dd")
				}


			},

			/**
			 * 提交前验证事件
			 * @param {Object} 请求参数
			 * @return {String} 验证成功返回null, 失败返回错误提示
			 */
			submit_check(param) {
				let msg = null
																																				return msg;
			},

			is_view(){
				var bl = this.user_group == "管理员";

				return bl;
			},
			/**
			 * 上传文件
			 * @param {Object} param
			 */
			uploadimg(param) {
				this.uploadFile(param.file, "avatar");
			},

		},
		created() {
											this.get_list_user_course_teacher();
																	},
	}
</script>

<style>
	.avatar-uploader .el-upload {
		border: 1px dashed #d9d9d9;
		border-radius: 6px;
		cursor: pointer;
		position: relative;
		overflow: hidden;
	}

	.avatar-uploader .el-upload:hover {
		border-color: #409EFF;
	}

	.avatar-uploader-icon {
		font-size: 28px;
		color: #8c939d;
		width: 178px;
		height: 178px;
		line-height: 178px;
		text-align: center;
	}

	.avatar {
		width: 178px;
		height: 178px;
		display: block;
	}




</style>
